package com.heima.wemedia.common;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.heima.utils.thread.WmThreadLocalUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.Date;

/**
 * 这个是元数据自动填充的工具类
 * 能够帮我们直接填充一些公共字段
 *
 * @author 10161
 */
@Component
@Slf4j
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        /*metaObject.setValue("userId", 1102);
        metaObject.setValue("createdTime", new Date());
        metaObject.setValue("submitedTime",new Date());
        metaObject.setValue("publishTime",new Date());*/
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("公共字段update填充功能已开启");
       /* *//*metaObject.setValue("userId", WmThreadLocalUtil.getUser().getApUserId());*//*
        metaObject.setValue("submitedTime",new Date());
        metaObject.setValue("publishTime",new Date());*/

    }

}
